<template>
  <a-modal
    title="修改您的密码"
    v-model="show"
    @ok="handleSubmit"
  >
    <a-form :form="form">
      <a-form-item label="新密码" v-bind="formItemLayout">
        <a-input placeholder="新密码" v-decorator="field('pwd','新密码')"/>
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<script>
import { field } from '@/utils/util'
import { updatePassword } from '@/api/user'
import md5 from 'md5'
export default {
  name: 'UpdatePasswordDialog',
  data () {
    return {
      show: false,
      form: this.$form.createForm(this),
      formItemLayout: {
        labelCol: { span: 6 },
        wrapperCol: { span: 14 }
      }

    }
  },
  methods: {
    field,
    open () {
      this.show = true
    },
    handleSubmit () {
      this.form.validateFields((err, values) => {
        if (!err) {
          const data = {
            pwd: md5(values.pwd)
          }
          updatePassword(data).then(() => {
            this.$message.success('更新密码成功')
            this.show = false
          })
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
